package com.bigshen.demo.annotation.configurecomponents.a6LifeCycle;

import com.bigshen.demo.project.entity.lifecycle.Car;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;


@Configuration
@ComponentScans({
    @ComponentScan("com.bigshen.demo.project.entity"),
    @ComponentScan("com.bigshen.demo.annotation.configurecomponents.a6LifeCycle"),
})
public class MyConfig {

    /**
     *  bean的生命周期 ： 创建(实例化-初始化)、使用、销毁
     * 3中方式都可实现 对生命周期进行控制：
     * a、@PostConstruct、@PreDestroy
     * b、@Bean本身的 initMethod()、destroyMethod()
     * c、接口 InitializingBean#afterPropertiesSet()、DisposableBean#destroy()
     * @return
     */
    @Bean(initMethod = "addOil", destroyMethod = "release")
    public Car car() {
        return new Car();
    }

}
